package com.PAT.UnSatisfying;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/12/22/15:55
 * @Description:
 * @Target: 差3
 */
public class 有理数四则运算 {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String s1 = in.next();
        String s2 = in.next();

        String[] split1 = s1.split("/");
        String[] split2 = s2.split("/");

        long a1 = Integer.valueOf(split1[0]);
        long a2 = Integer.valueOf(split1[1]);

        long b1 = Integer.valueOf(split2[0]);
        long b2 = Integer.valueOf(split2[1]);

        System.out.println(dealGcd(a1,a2)+" + "+dealGcd(b1,b2)+" = "+dealGcd(a1*b2+a2*b1,a2*b2));
        System.out.println(dealGcd(a1,a2)+" - "+dealGcd(b1,b2)+" = "+dealGcd(a1*b2-a2*b1,a2*b2));
        System.out.println(dealGcd(a1,a2)+" * "+dealGcd(b1,b2)+" = "+dealGcd(a1*b1,a2*b2));
        if (b1!=0){
            System.out.println(dealGcd(a1,a2)+" / "+dealGcd(b1,b2)+" = "+dealGcd(a1*b2,a2*b1));
        }else {
            System.out.println(dealGcd(a1,a2)+" / "+dealGcd(b1,b2)+" = "+"Inf");
        }

    }


    public static String dealGcd(long x,long y){
        String ss = "";
        boolean flag = false;
        if (x<0||y<0){
            flag = true;
            ss+="(-";
            x=x<0?-x:x;
            y=y<0?-y:y;
        }
        long gcd = gcd(x,y);


        if (x==1&&y==1){
            ss+="1";
        }else if (y==1){
            ss+=x;
        }else if (gcd==1){

            long a = x/gcd;
            long b = y/gcd;
            long u = a%b;
            long k = (a-u)/b;
            if (k!=0){
                ss+=k+" ";
                ss+=(u);
                ss+="/";
                ss+=(b);
            }else {
                ss+=(a);
                ss+="/";
                ss+=(b);
            }
        }else {

            if (gcd == y){
                ss+=x/gcd;
            }else {
                long a = x/gcd;
                long b = y/gcd;
                long u = a%b;
                long k = (a-u)/b;
                if (k!=0){
                    ss+=k+" ";
                    ss+=(u);
                    ss+="/";
                    ss+=(b);
                }else {
                    ss+=(a);
                    ss+="/";
                    ss+=(b);
                }

            }

        }


        if (flag==true){
            ss+=")";
        }
        return ss;

    }

    public static long gcd(long q,long p){
        if (p == 0){
            return q;
        }

        long r = q % p ;
        return gcd(p,r);
    }
}
